<template>
  <div>
<van-nav-bar
  title="微博登录"
  left-text="返回"
  right-text="按钮"
  left-arrow
/>
<center><p></p><h3 style="font-family: 华文行楷;">检测到您是第一次登录，请绑定手机号</h3>
<div class="aaa">

<el-input placeholder="请输入您的手机号" v-model="mobile"></el-input>
<p></p>
<el-select v-model="value" placeholder="请选择您的身份">
    <el-option
      v-for="item in rolelist"
      :key="item.id"
      :label="item.name"
      :value="item.id">
    </el-option>
  </el-select>
  <el-button @click="Go">点击提交</el-button>


</div>
</center>
<van-tabbar>
  <van-tabbar-item icon="home-o">主页</van-tabbar-item>
  <van-tabbar-item icon="search">搜索</van-tabbar-item>
  <van-tabbar-item icon="friends-o">好友</van-tabbar-item>
  <van-tabbar-item icon="setting-o">设置</van-tabbar-item>
</van-tabbar>
  </div>
</template>

<script>
export default {
    data(){
        return{
            token:this.$route.query.token,
            uid:this.$route.query.uid,
            value:'',
            rolelist:[],
            mobile:''
        }
    },
    methods:{
    getrole(){
      this.axios.get("get_role/").then((cg)=>{
        this.rolelist=(cg.data.msg)

      })
    },
    Go(){
      var pdcode=/^1[3-9]\d{9}$/
      if(!pdcode.test(this.mobile)){
        alert("手机号格式错误")
        return
      }
      if(this.value=="" ||this.value==null){
        alert("您需要选择当前身份，如果您已有该平台账号，并不会影响您的身份")
        return
      }
      this.axios.post("add_sf_login/",{mobile:this.mobile,uid:this.uid,token:this.token,roleid:this.value}).then((cg)=>{
        if(cg.data.code==200){
            localStorage.setItem("token",cg.data.token)
            localStorage.setItem("userid",cg.data.userid)
            localStorage.setItem("role_list",JSON.stringify(cg.data.role_list))
            alert("绑定成功")
            return
        }else{
            alert("绑定失败，请联系客服或管理员")
        }
        
      })

    }
    },
    mounted(){
        this.getrole()
    }

}
</script>

<style>

</style>